class Solution
{
public:
    int minimumCardPickup(vector<int> &cards)
    {
        unordered_map<int, int> last;
        int ret = INT_MAX;

        for (int i = 0; i < cards.size(); i++)
        {
            if (last.count(cards[i]))
            {
                ret = min(ret, i - last[cards[i]] + 1);
            }
            last[cards[i]] = i;
        }
        return ret == INT_MAX ? -1 : ret;
    }
};